;;; Required packages: nasm, gcc, gcc-multilib
;;; Compile commands:
;;;     nasm -f elf 04-if.asm -o bin/04-if.o
;;;     gcc -m32 -o bin/04-if bin/04-if.o
;;;
section .data 
    x dd 1000
    y dd 2000

    fmt_x_greater_then_y db "x is greater then y", 0xa, 0
    fmt_y_greater_then_x db "y is greater then x", 0xa, 0
    fmt_x_equals_y db "x and y are equal", 0xa, 0

section .text 
    extern printf 
    global main

main:
    ; jg  - jump if greater
    ; jl  - jump if less
    ; jge - jump if greater or equals
    ; jle - jump if less or equals
    ; je  - jump if equals
    ; jne - jump if not equals 
    ; jmp - jump in any case

    mov eax, DWORD [x]
    mov ebx, DWORD [y]
    cmp eax, ebx
    jg .xGreaterThenY ; jump to the label in case if eax > ebx

    mov eax, DWORD [x]
    mov ebx, DWORD [y]
    cmp eax, ebx 
    jl .yGreaterThenX ; jump to the label in case if eax < ebx

    jmp .xEqualsY

.xGreaterThenY: ; '.' character before label name created local label main.xGreaterThenY
    push fmt_x_greater_then_y
    call printf
    add esp, 4
    jmp .done

.yGreaterThenX:
    push fmt_y_greater_then_x
    call printf
    add esp, 4
    jmp .done 

.xEqualsY:
    push fmt_x_equals_y
    call printf
    add esp, 4
    jmp .done

.done: 
    ; exit code 
    mov eax, 1 ; 1 - system call sys_exit
    mov ebx, 0 ; 0 - error code 0
    int 0x80 ; processor interruption to run syscall 